# -*- coding: utf-8 -*-
#
# Copyright © 2013 Lucian Smith
# Based on the 'pylint' plugin
# (see spyderlib/__init__.py for details)

"""Hello widget"""

from __future__ import with_statement, print_function

from spyderlib.qt.QtGui import (QHBoxLayout, QWidget,
                                QVBoxLayout, QLabel)
from spyderlib.qt.QtCore import QTextCodec
from spyderlib.widgets.sourcecode.base import TextEditBaseWidget
from spyderlib.widgets.editor import EditorWidget
locale_codec = QTextCodec.codecForLocale()

import sys

# Local imports
from spyderlib.utils.qthelpers import get_icon, create_toolbutton
from spyderlib.baseconfig import get_conf_path, get_translation
_ = get_translation("p_pylint", dirname="spyderplugins")


class HelloEditor(TextEditBaseWidget):
    def __init__(self, parent):
        TextEditBaseWidget.__init__(self, parent)
        
    def clear_results(self):
        self.clear()
        

class HelloWidget(QWidget):
    """
    Hello widget
    """
    DATAPATH = get_conf_path('pylint.results')
    VERSION = '0.0.1'
    
    def __init__(self, parent, hello_number=1):
        QWidget.__init__(self, parent)
        
        self.setWindowTitle("Hello World")
        
        self.output = None
        self.error_output = None
        
        self.hello_number = hello_number

        self.start_button = create_toolbutton(self, icon=get_icon('run.png'),
                                    text=_("Say Hello"),
                                    tip=_("print 'hello world' 1-10 times"),
                                    triggered=self.start, text_beside_icon=True)

        self.ratelabel = QLabel()
        self.datelabel = QLabel()
        self.outwidget = HelloEditor(self)
        
        hlayout1 = QHBoxLayout()
        hlayout1.addWidget(self.start_button)

        layout = QVBoxLayout()
        layout.addLayout(hlayout1)
        layout.addWidget(self.outwidget)
        self.setLayout(layout)
        
    def start(self):
        for i in range(0, self.hello_number):
            self.outwidget.appendPlainText("Hello, world!")

def test():
    """Run pylint widget test"""
    from spyderlib.utils.qthelpers import qapplication
    app = qapplication()
    widget = HelloWidget(None)
    widget.show()
    widget.analyze(__file__)
    sys.exit(app.exec_())
    
if __name__ == '__main__':
    test()
